/**
 * Description:
 * Class Name:MyClient
 * Date:2022/5/24 9:21
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第17章_网络编程._17_3_基于TCP协议的网络编程._17_3_4_为服务器加入多线程;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

public class MyClient {
    public static void main(String[] args) throws Exception{
        String targetIP = "localhost";
        int targetPort = 30000;
        var socket = new Socket(targetIP, targetPort);
        // 客户端启动ClientThread线程不断地读取来自服务器的数据
        new Thread(new ClientThread(socket)).start();
        // 获取该Socket对应的输出流
        var ps = new PrintStream(socket.getOutputStream());
        String line = null;
        // 不断读取键盘输入
        var br = new BufferedReader(new InputStreamReader(System.in));
        while ((line = br.readLine()) != null){
            // 将用户的键盘输入内容写入Socket对应的输出流
            ps.println(line);
        }
    }
}
